home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / mui2c / number.m < prev    next >
Encoding:
Text File  |  1996-06-22  |  1.4 KB  |  80 lines

  1. Class (Number::MUIC_Text):0x165ff000
  2.  
  3. /*************************
  4. ** Custom Class: Number **
  5. **************************
  6. ** Number is a subclass of MUIC_Text that adds two new attributes:
  7. ** MUIA_Number_Contents [.SG]: takes a pointer to a double precision floating point number.
  8. **      This number will then be displayed by the object. If you get() this attribute,
  9. **      you must supply the address of a pointer to double.
  10. ** MUIA_Number_Digits [.SG]  : the number of decimal places used to display the number.
  11. */
  12.  
  13. #include <libraries/mui.h>
  14.  
  15. #include <proto/exec.h>
  16. #include <proto/muimaster.h>
  17. #include <proto/utility.h>
  18.  
  19. #include <stdio.h>
  20. #include <math.h>
  21.  
  22. Data (struct NumberData)
  23.  
  24. struct NumberData
  25. {
  26.     double last,diff;
  27.     char digits;
  28. };
  29.  
  30. Method(OM_NEW)
  31. {
  32.     data->last = 0.0;
  33.     data->digits = 2;
  34.     data->diff = pow(10.0, (double) -data->digits);
  35. }
  36.  
  37. Method(OM_SET)
  38. {
  39.     static char buf[16];
  40.     double this;
  41.  
  42.     Attributes
  43.     {
  44.         MUIA_Number_Contents*:public
  45.         {
  46.             this = *((double *) tag->ti_Data);
  47.  
  48.             if (fabs(data->last - this) >= data->diff){
  49.                 sprintf(buf, MUIX_R"%.*lf", data->digits, this);
  50.                 set(obj, MUIA_Text_Contents, buf);
  51.  
  52.                 data->last = this;
  53.             }
  54.         }
  55.  
  56.         MUIA_Number_Digits:public
  57.         {
  58.             data->digits = (char) tag->ti_Data;
  59.             data->diff = pow(10.0, (double) -data->digits);
  60.         }
  61.     }
  62. }
  63.  
  64.  
  65. Method(OM_GET)
  66. {
  67.     Attributes
  68.     {
  69.         MUIA_Number_Contents:public
  70.         {
  71.             *store = (ULONG) &(data->last);
  72.         }
  73.  
  74.         MUIA_Number_Digits:public
  75.         {
  76.             *store = (ULONG) data->last;
  77.         }
  78.     }
  79. }
  80.